package com.mh.study.jackson.annotations;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author meng.han
 * @since 2021-11-26
 */
@JsonDeserialize(using = EventWithSerializer1.CustomDateDeserializer.class)
public class EventWithSerializer1 {

    public String name;
//    public Date eventDate;
    public String eventDescribe;

    public EventWithSerializer1() {
    }

    public EventWithSerializer1(String name, String eventDescribe) {
        this.name = name;
        this.eventDescribe = eventDescribe;
    }

    public static class CustomDateDeserializer
            extends StdDeserializer<EventWithSerializer1> {

        public CustomDateDeserializer() {
            this(null);
        }

        protected CustomDateDeserializer(Class<?> vc) {
            super(vc);
        }


        @Override
        public EventWithSerializer1 deserialize(JsonParser p, DeserializationContext ctxt)
                throws IOException, JsonProcessingException {
            System.out.println(p.getText());
            return null;
        }
    }
}
